import http from "@/axios/http";

// 定义基础URL
const BASE_URL = "http://192.140.166.207:8088/api/role";

// 统一的请求处理函数
const handleRequest = async (url, params) => {
    try {
        const res = await http.post(url, params);
        if (res.code === 200) {
            return res.data;
        }
        throw new Error(res.message || '请求失败');
    } catch (error) {
        console.error(`API请求错误: ${error.message}`, error);
        throw error;
    }
};

const role = {
    select: (params) => handleRequest(`${BASE_URL}/select`, params),
    insert: (params) => handleRequest(`${BASE_URL}/insert`, params),
    update: (params) => handleRequest(`${BASE_URL}/update`, params),
    delete: (params) => handleRequest(`${BASE_URL}/delete`, params),
};

export default role;